{# SPDX-License-Identifier: Apache-2.0 -#}

{% extends "admin/base.html" %}

{% import "admin/utils/pagination.html" as pagination %}

{% block title %}{{ project.name }}{% endblock %}

{% block breadcrumb %}
  <li class="breadcrumb-item"><a href="{{ request.route_path('admin.project.list') }}">Projects</a></li>
  <li class="breadcrumb-item active">{{ project.name }}</li>
{% endblock %}

{% block content %}
  {% if project.lifecycle_status == 'quarantine-enter' %}
    <div class="card card-danger">
      <div class="card-header">
        <h3 class="card-title">
          <i class="icon fas fa-ban"></i> Quarantined
        </h3>
        <div class="card-tools">
          <span class="time">
            <i class="fas fa-clock"></i> <time datetime="{{ project.lifecycle_status_changed }}" title="{{ project.lifecycle_status_changed }}">{{ project.lifecycle_status_changed }}</time>
          </span>
        </div>
      </div>
      <div class="card-body">
        <p>
          This project is quarantined.
          It should not be pip-installable nor appear in searches.
        </p>
        <p>Note: {{ project.lifecycle_status_note }}</p>
        <p>See Project Observations below for more details.</p>
      </div>
      <div class="card-footer">
        <div class="row">
          <div class="col">
            <button type="submit"
                    class="btn btn-block btn-outline-success"
                    data-toggle="modal"
                    data-target="#modal-exit-quarantine">Clear from Quarantine</button>
          </div>
          <div class="col">
            <form class="form-inline" method="GET" action="{{ request.route_path('admin.prohibited_project_names.add') }}">
              <input name="project" type="hidden" value="{{ project.name }}">
              <input name="comment" type="hidden" value="malware" id="prohibitedComment">
              <button type="submit" class="btn btn-block btn-outline-danger">Remove project as malware</button>
            </form>
          </div>
        </div>
      </div>
    </div>
    <!-- .card -->

   <div class="modal fade" id="modal-exit-quarantine">
    <div class="modal-dialog modal-exit-quarantine">
      <form id="exit-quarantine"
            action="{{ request.route_path('admin.project.remove_from_quarantine', project_name=project.name) }}"
            method="post">
        <input name="csrf_token"
               type="hidden"
               value="{{ request.session.get_csrf_token() }}">
        <div class="modal-content">
          <div class="modal-header bg-success">
            <h4 class="modal-title">Remove Project from Quarantine</h4>
            <button type="button" class="close" data-dismiss="modal" aria-label="Close">
              <span aria-hidden="true">×</span>
            </button>
          </div>
          <div class="modal-body">
            <p>
              Confirming that <code>{{ project.name }}</code> is no longer in quarantine.
            </p>
            <p>
              This will restore the project to the index for installation and
            </p>
          </div>
          <div class="modal-footer justify-content-between">
            <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
            <button type="submit" class="btn btn-outline-success">Remove from Quarantine</button>
          </div>
        </div>
      </form>
    </div>
  </div>
  <!-- /.modal -->

  {% elif project.lifecycle_status in ["archived", "archived-noindex"] %}
    <div class="card card-info">
      <div class="card-header">
        <h3 class="card-title">
          <i class="icon fas fa-info-circle"></i> Archived
        </h3>
        <div class="card-tools">
          <span class="time">
            <i class="fas fa-clock"></i> <time datetime="{{ project.lifecycle_status_changed }}" title="{{ project.lifecycle_status_changed }}">{{ project.lifecycle_status_changed }}</time>
          </span>
        </div>
      </div>
      <div class="card-body">
        <p>
          This project is archived.
          It should not allow any new uploads unless it's unarchived.
        </p>
      </div>
    </div>
    <!-- .card -->

  {% endif %}

<div class="card card-primary" id="attributes">
  <div class="card-header">Attributes</div>
  <div class="card-body">
    <div class="table-responsive p-0">
      <table class="table table-hover">
        <thead>
        <tr>
          <th>Attribute</th>
          <th>Value</th>
          <th>Set a new value<th>
          <th><th>
        </tr>
        </thead>
        <tbody>
        <tr>
          <td>Total size</td>
          <td>{{ project.total_size|filesizeformat(binary=True) }}</td>
          <td></td>
          <td></td>
        </tr>
        <tr>
          <td rowspan="2">Upload limit</td>
          <td colspan="3">
            {# Calculate effective limit #}
            {% set effective_upload_limit = MAX_FILESIZE %}
            {% set limit_source = "system default" %}
            {% if project.upload_limit and project.upload_limit > effective_upload_limit %}
              {% set effective_upload_limit = project.upload_limit %}
              {% set limit_source = "project" %}
            {% endif %}
            {% if project.organization and project.organization.upload_limit and project.organization.upload_limit > effective_upload_limit %}
              {% set effective_upload_limit = project.organization.upload_limit %}
              {% set limit_source = "organization" %}
            {% endif %}

            <div class="alert alert-info">
              <strong>Effective limit: {{ effective_upload_limit|filesizeformat(binary=True) }}</strong> (from {{ limit_source }})
            </div>

            <table class="table table-sm table-bordered">
              <tr>
                <td>System default:</td>
                <td>{{ MAX_FILESIZE|filesizeformat(binary=True) }}</td>
                <td><small class="text-muted">Not configurable</small></td>
              </tr>
              <tr>
                <td>Project limit:</td>
                <td>
                  {% if project.upload_limit %}
                    {{ project.upload_limit|filesizeformat(binary=True) }}
                  {% else %}
                    <span class="text-muted">Not set</span>
                  {% endif %}
                  {% if limit_source == "project" %}<span class="badge badge-success">Active</span>{% endif %}
                </td>
                <td><small class="text-muted">Configure below</small></td>
              </tr>
              {% if project.organization %}
              <tr>
                <td>Organization limit:</td>
                <td>
                  {% if project.organization.upload_limit %}
                    {{ project.organization.upload_limit|filesizeformat(binary=True) }}
                  {% else %}
                    <span class="text-muted">Not set</span>
                  {% endif %}
                  {% if limit_source == "organization" %}<span class="badge badge-success">Active</span>{% endif %}
                </td>
                <td><a href="{{ request.route_path('admin.organization.detail', organization_id=project.organization.id) }}#organization-limits" class="btn btn-xs btn-outline-primary">Edit in organization</a></td>
              </tr>
              {% endif %}
            </table>
          </td>
        </tr>
        <tr>
          <form method="POST" action="{{ request.route_path('admin.project.set_upload_limit', project_name=project.normalized_name) }}">
            <input name="csrf_token" type="hidden" value="{{ request.session.get_csrf_token() }}">
            <td colspan="3">
              <div class="form-inline">
                <label for="uploadLimit" class="mr-3">Set project limit:</label>
                {% if project.upload_limit %}
                {% set upload_limit_value = project.upload_limit / ONE_MIB %}
                {% else %}
                {% set upload_limit_value = '' %}
                {% endif %}
                <input type="number" name="upload_limit" id="uploadLimit" class="form-control form-control-sm mr-2" min="{{ MAX_FILESIZE / ONE_MIB }}" max="{{ UPLOAD_LIMIT_CAP / ONE_MIB }}" step=1 value="{{ upload_limit_value|int }}">
                <span class="mr-3">MiB</span>
                <button type="submit" class="btn btn-primary btn-sm">Update</button>
                {% if project.upload_limit and limit_source != "project" %}
                  <small class="text-warning ml-3">⚠️ This limit is overridden by a more generous {{ limit_source }} limit</small>
                {% endif %}
              </div>
            </td>
          </form>
        </tr>
        <tr>
          <td rowspan="2">Total size limit</td>
          <td colspan="3">
            {# Calculate effective limit #}
            {% set effective_total_size_limit = MAX_PROJECT_SIZE %}
            {% set size_limit_source = "system default" %}
            {% if project.total_size_limit and project.total_size_limit > effective_total_size_limit %}
              {% set effective_total_size_limit = project.total_size_limit %}
              {% set size_limit_source = "project" %}
            {% endif %}
            {% if project.organization and project.organization.total_size_limit and project.organization.total_size_limit > effective_total_size_limit %}
              {% set effective_total_size_limit = project.organization.total_size_limit %}
              {% set size_limit_source = "organization" %}
            {% endif %}

            <div class="alert alert-info">
              <strong>Effective limit: {{ effective_total_size_limit|filesizeformat(binary=True) }}</strong> (from {{ size_limit_source }})
            </div>

            <table class="table table-sm table-bordered">
              <tr>
                <td>System default:</td>
                <td>{{ MAX_PROJECT_SIZE|filesizeformat(binary=True) }}</td>
                <td><small class="text-muted">Not configurable</small></td>
              </tr>
              <tr>
                <td>Project limit:</td>
                <td>
                  {% if project.total_size_limit %}
                    {{ project.total_size_limit|filesizeformat(binary=True) }}
                  {% else %}
                    <span class="text-muted">Not set</span>
                  {% endif %}
                  {% if size_limit_source == "project" %}<span class="badge badge-success">Active</span>{% endif %}
                </td>
                <td><small class="text-muted">Configure below</small></td>
              </tr>
              {% if project.organization %}
              <tr>
                <td>Organization limit:</td>
                <td>
                  {% if project.organization.total_size_limit %}
                    {{ project.organization.total_size_limit|filesizeformat(binary=True) }}
                  {% else %}
                    <span class="text-muted">Not set</span>
                  {% endif %}
                  {% if size_limit_source == "organization" %}<span class="badge badge-success">Active</span>{% endif %}
                </td>
                <td><a href="{{ request.route_path('admin.organization.detail', organization_id=project.organization.id) }}#organization-limits" class="btn btn-xs btn-outline-primary">Edit in organization</a></td>
              </tr>
              {% endif %}
            </table>
          </td>
        </tr>
        <tr>
          <form method="POST" action="{{ request.route_path('admin.project.set_total_size_limit', project_name=project.normalized_name) }}">
            <input name="csrf_token" type="hidden" value="{{ request.session.get_csrf_token() }}">
            <td colspan="3">
              <div class="form-inline">
                <label for="totalSizeLimit" class="mr-3">Set project limit:</label>
                {% if project.total_size_limit %}
                {% set total_size_limit_value = project.total_size_limit // ONE_GIB %}
                {% else %}
                {% set total_size_limit_value = '' %}
                {% endif %}
                <input type="number" name="total_size_limit" id="totalSizeLimit" class="form-control form-control-sm mr-2" min="{{ MAX_PROJECT_SIZE // ONE_GIB }}" value="{{total_size_limit_value}}">
                <span class="mr-3">GiB</span>
                <button type="submit" class="btn btn-primary btn-sm">Update</button>
                {% if project.total_size_limit and size_limit_source != "project" %}
                  <small class="text-warning ml-3">⚠️ This limit is overridden by a more generous {{ size_limit_source }} limit</small>
                {% endif %}
              </div>
            </td>
          </form>
        </tr>
        </tbody>
      </table>
    </div>
  </div>
</div> <!-- .card #attributes -->

{% if project.organization %}
<div class="card card-secondary" id="organization">
  <div class="card-header">Organization</div>
  <div class="card-body">
    <div class="table-responsive p-0">
      <table class="table table-hover table-striped">
        <thead>
          <tr>
            <th>Name</th>
            <th>Account Name</th>
            <th>Active</th>
            <th>Good Standing</th>
          </tr>
        </thead>
        <tbody>
          <tr>
            <td><a href="{{ request.route_path('admin.organization.detail', organization_id=project.organization.id) }}">{{ project.organization.display_name }}</a></td>
            <td>{{ project.organization.name }}</td>
            <td>{{ project.organization.is_active }}</td>
            <td>{{ project.organization.good_standing }}</td>
          </tr>
        </tbody>
      </table>
    </div>
  </div>
</div>
{% endif %}

<div class="card card-secondary" id="maintainers">
  <div class="card-header">
    <div class="card-title">Maintainers</div>
    <div class="card-tools">
      {% if maintainers %}
      <span class="badge badge-primary">{{ maintainers|length }}</span>
      {% endif %}
      <button type="button" class="btn btn-tool" data-card-widget="collapse"><i class="fas fa-plus"></i>
      </button>
    </div>
  </div>
  <div class="card-body">
    <div class="table-responsive p-0">
      <table class="table table-hover table-striped">
        <thead>
          <tr>
            <th>Username</th>
            <th>Role</th>
            <th></th>
          </tr>
        </thead>
        <tbody>
          {% for role in maintainers %}
          <tr>
            <td><a href="{{ request.route_path('admin.user.detail', username=role.user.username) }}">{{ role.user.username }}</a></td>
            <td>{{ role.role_name }}</td>
            <td>
              <button type="button" class="btn btn-danger" data-toggle="modal" data-target="#deleteRoleModal-{{ role.id }}" {{ "disabled" if not request.has_permission(Permissions.AdminRoleDelete) }}>
              <i class="fa fa-trash"></i>
              </button>
              <div class="modal fade" id="deleteRoleModal-{{ role.id }}" tabindex="-1" role="dialog">
                <form method="POST" action="{{ request.route_path('admin.project.delete_role', project_name=project.name, role_id=role.id) }}">
                  <input name="csrf_token" type="hidden" value="{{ request.session.get_csrf_token() }}">
                  <div class="modal-dialog" role="document">
                    <div class="modal-content">
                      <div class="modal-header">
                        <h4 class="modal-title" id="exampleModalLabel">Remove role for {{ role.user.username }}?</h4>
                        <button type="button" class="close" data-dismiss="modal">
                          <span>&times;</span>
                        </button>
                      </div>
                      <div class="modal-body">
                        <p>
                          This will remove the role for the user.
                        </p>
                        <hr>
                        <p>
                          To delete role "{{ role.role_name }}" for "{{role.user.username}}", type the username:
                        </p>
                        <input type="text" name="username" placeholder="{{ role.user.username }}" required>
                      </div>
                      <div class="modal-footer">
                        <button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
                        <button type="submit" class="btn btn-danger">Delete</button>
                      </div>
                    </div>
                  </div>
                </form>
              </div>
            </td>
          </tr>
          {% endfor %}

          <tr id="add_role">
            <form method="POST" action="{{ request.route_path('admin.project.add_role', project_name=project.name) }}">
              <input name="csrf_token" type="hidden" value="{{ request.session.get_csrf_token() }}">
              <td>
                <input name="username" class="form-control" placeholder="Username" required {{ "disabled" if not request.has_permission(Permissions.AdminRoleAdd) }}>
              </td>
              <td>
                <select class="form-control" name="role_name" required {{ "disabled" if not request.has_permission(Permissions.AdminRoleAdd) }}>
                <option disabled selected>Select a role</option>
                {% for role_name in ['Maintainer', 'Owner'] %}
                <option value="{{ role_name }}">
                  {{ role_name }}
                </option>
                {% endfor %}
                </select>
              </td>
              <td>
                <button type="submit" class="btn btn-primary" {{ "disabled" if not request.has_permission(Permissions.AdminRoleAdd) }}>
                <i class="fa fa-plus"></i>
                </button>
              </td>
            </form>
          </tr>
        </tbody>
      </table>
    </div>
  </div>
</div>

<div class="card card-secondary" id="invitations">
  <div class="card-header">Invitations</div>
  <div class="card-body">
  <div class="table-responsive p-0">
        <table class="table table-hover table-striped">
          <thead>
            <tr>
              <th>Username</th>
              <th>Status</th>
            </tr>
          </thead>
          <tbody>
            {% for invitation in project.invitations %}
            <tr>
              <td><a href="{{ request.route_path('admin.user.detail', username=invitation.user.username) }}">{{ invitation.user.username }}</a></td>
              <td>{{ invitation.invite_status.value }}</td>
            </tr>
            {% endfor %}
          </tbody>
        </table>
    </div>
  </div>
</div>

<div class="card card-info" id="releases">
  <div class="card-header">
    <h3 class="card-title">Releases</h3>
    <div class="card-tools">
      {% if releases %}
      <span class="badge badge-secondary">{{ releases|length }}</span>
      {% endif %}
    </div>
  </div>
  <div class="card-body">
    <div class="table-responsive p-0">
      <table class="table table-hover table-striped">
        <thead>
          <tr>
            <th>Release version</th>
            <th>Created</th>
            <th>Uploader</th>
            <th>Author email</th>
            <th>Observations</th>
          </tr>
        </thead>
        <tbody>
          {% for release in releases %}
          <tr>
            <td><a href="{{ request.route_path('admin.project.release', project_name=release.project.normalized_name, version=release.version) }}">{{ release.project.name }}-{{ release.version }}</a></td>
            <td>{{ release.created }}</td>
            <td>
              {% if release.uploader %}
              <a href="{{ request.route_path('admin.user.detail', username=release.uploader.username) }}">{{ release.uploader.username }}</a>
              {% endif %}
            </td>
            <td>{{ release.author_email }}</td>
            <td>{{ release.observations|length }}</td>
          </tr>
          {% endfor %}
        </tbody>
      </table>
    </div>
  </div>
  <div class="card-footer">
    <a href="{{ request.route_path('admin.project.releases', project_name=project.normalized_name) }}">All releases</a>
  </div>
</div> <!-- .card #releases -->

<div class="card card-info" id="oidc-publishers">
  <div class="card-header">OpenID Connect Publishers</div>
  <div class="card-body">
    {% if oidc_publishers %}
    <div class="table-responsive p-0">
      <table class="table table-hover table-striped">
        <thead>
          <tr>
            <th>Publisher</th>
            <th>Configuration</th>
            <th>URL</th>
          </tr>
        </thead>
        <tbody>
          {% for pub in oidc_publishers %}
          <tr>
            <td><strong>{{ pub.publisher_name }}</strong></td>
            <td>
              {% if pub.admin_details %}
                <dl class="mb-0">
                  {% for label, value in pub.admin_details %}
                    <dt class="small d-inline-block">{{ label }}:</dt>
                    <dd class="small d-inline"><code>{{ value }}</code></dd>
                    <br>
                  {% endfor %}
                </dl>
              {% else %}
                <code>{{ pub }}</code>
              {% endif %}
            </td>
            <td>
              {% if pub.publisher_url() %}
                <a href="{{ pub.publisher_url() }}" target="_blank">{{ pub.publisher_url() }}</a>
              {% else %}
                <span class="text-muted">N/A</span>
              {% endif %}
            </td>
          </tr>
          {% endfor %}
        </tbody>
      </table>
    </div>
    {% else %}
    No publishers configured.
    {% endif %}
  </div>
</div> <!-- .card #oidc-publishers -->

<div class="card card-info" id="alternate-repositories">
  <div class="card-header">Alternate Repositories</div>
  <div class="card-body">
    {% if project.alternate_repositories %}
    <div class="table-responsive p-0">
      <table class="table table-hover table-striped">
        <thead>
          <tr>
            <th>Repo name</th>
            <th>URL</th>
            <th>Description</th>
          </tr>
        </thead>
        <tbody>
          {% for alt_repo in project.alternate_repositories %}
          <tr>
            <td>{{ alt_repo.name }}</td>
            <td><a href="{{ alt_repo.url }}">{{ alt_repo.url }}</a></td>
            <td>{{ alt_repo.description }}</td>
          </tr>
          {% endfor %}
        </tbody>
      </table>
    </div>
    {% else %}
    No alternate repositories configured.
    {% endif %}
  </div>
</div> <!-- .card #oidc-publishers -->

<div class="card card-primary card-outline collapsed-card" id="project_observations">
  <div class="card-header">
    <h3 class="card-title">Project Observations</h3>
    <div class="card-tools">
      {% if observations %}
      <span class="badge badge-warning">{{ observations|length }}</span>
      {% endif %}
      <button type="button" class="btn btn-tool" data-card-widget="collapse"><i class="fas fa-plus"></i>
      </button>
    </div>
  </div>

  <div class="card-body">
    {% if observations %}
    {# TODO: Make this dataTables-enabled for sorting, filtering, etc. See Account Activity for an example. #}
    <div class="table-responsive p-0">
      <table class="table table-hover table-striped">
        <thead>
          <tr>
            <th></th>
            <th>Created</th>
            <th>Kind</th>
            <th>Reporter</th>
            <th>Summary</th>
          </tr>
        </thead>
        <tbody>
          {% for observation in observations %}
          <tr>
            <td>
              <a href="{{ request.route_path('admin.malware_reports.detail', observation_id=observation.id) }}">
                <i class="fa-regular fa-eye"></i>
              </a>
            </td>
            <td>{{ observation.created }}</td>
            {# TODO: There's no exact relationship back to the ObservationKind to get the human-string. Not exactly sure how to get that yet. #}
            <td>{{ observation.kind }}</td>
            <td>
              {# TODO: This won't work yet for non-User Observers #}
              <a href="{{ request.route_path('admin.user.detail', username=observation.observer.parent.username) }}">{{ observation.observer.parent.username }}</a>
            </td>
            <td>{{ observation.summary }}</td>
          </tr>
          {% endfor %}
        </tbody>
      </table>
    </div>
    {% else %}
    No observations.
    {% endif %}
  </div>
  <div class="card-footer">
    <a class="text-center" href="{{ request.route_path('admin.project.observations', project_name=project.name) }}">All observations</a>
    <button type="button" class="btn btn-outline-primary float-right" data-toggle="modal" data-target="#addObservationModal">
      Add Observation
    </button>
    <div class="modal fade" id="addObservationModal" tabindex="-1" role="dialog">
      <form method="POST" action="{{ request.route_path('admin.project.add_project_observation', project_name=project.name) }}">
        <input name="csrf_token" type="hidden" value="{{ request.session.get_csrf_token() }}">
        <div class="modal-dialog modal-lg" role="document">
          <div class="modal-content">
            <div class="modal-header">
              <h4 class="modal-title" id="exampleModalLabel">Add Observation for {{ project.name }}</h4>
              <button type="button" class="close" data-dismiss="modal">
                <span>&times;</span>
              </button>
            </div>
            <div class="modal-body">
              <div class="row">
                <div class="col-auto">
                  <div class="form-group">
                    {% for observation_kind in observation_kinds %}
                    <div class="form-check">
                      <input class="form-check-input" type="radio" name="kind" id="{{ observation_kind.value[0] }}" value="{{ observation_kind.value[0] }}">
                      <label class="form-check-label" for="{{ observation_kind.value[0] }}" >
                        {{ observation_kind.value[1] }}
                      </label>
                    </div>
                    {% endfor %}
                  </div>
                </div>
                <div class="col">
                  <div class="form-group">
                    <label class="form-check-label" for="projectObservationText">What do we need to know?</label>
                    <textarea class="form-control" id="projectObservationText" name="summary" rows="3" placeholder="Enter ..."></textarea>
                  </div>
                </div>
              </div>
            </div>
            <div class="modal-footer">
              <button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
              <button type="submit" class="btn btn-info">Submit</button>
            </div>
          </div>
        </div>
      </form>
    </div> <!-- .modal #addObservationModal -->
  </div> <!-- .card-footer -->
</div> <!-- .card #project_observations -->

<div class="card card-primary card-outline collapsed-card" id="journals">
  <div class="card-header">
    <h3 class="card-title">Journals</h3>
    <div class="card-tools">
      {% if journal %}
      <span class="badge badge-secondary">{{ journal|length }}</span>
      {% endif %}
      <button type="button" class="btn btn-tool" data-card-widget="collapse"><i class="fas fa-plus"></i>
      </button>
    </div>
  </div>
  <div class="card-body">
    <div class="table-responsive p-0">
      <table class="table table-hover table-striped">
        <thead>
          <tr>
            <th>name</th>
            <th>version</th>
            <th>date</th>
            <th>submitted_by</th>
            <th>action</th>
          </tr>
        </thead>
        <tbody>
          {% for entry in journal %}
          <tr>
            <td>{{ entry.name }}</td>
            <td>{{ entry.version }}</td>
            <td>{{ entry.submitted_date }}</td>
            <td><a href="{{ request.route_path('admin.user.detail', username=entry.submitted_by.username) }}">{{ entry.submitted_by.username }}</a></td>
            <td>{{ entry.action }}</td>
          </tr>
          {% endfor %}
        </tbody>
      </table>
    </div>
  </div>
  <div class="card-footer">
    <a href="{{ request.route_path('admin.project.journals', project_name=project.normalized_name) }}">All journals</a>
  </div>
</div> <!-- .card #journals -->

<div class="card card-secondary card-outline collapsed-card" id="projectActivity">
  <div class="card-header">
    <h3 class="card-title">Project activity</h3>
    <div class="card-tools">
      <button type="button" class="btn btn-tool" data-card-widget="collapse"><i class="fas fa-plus"></i>
      </button>
    </div>
  </div>

  <div class="card-body">
    <table class="table table-hover">
      <thead>
        <tr>
          <th scope="col">Event</th>
          <th scope="col">Time</th>
          <th scope="col">IP address</th>
          <th scope="col">Hashed IP address</th>
          <th scope="col">Location Info</th>
          <th scope="col">User-Agent</th>
          <th scope="col">Additional information</th>
        </tr>
      </thead>
      <tbody>
        {% for event in project.events %}
        <tr>
          <td>{{ event.tag }}</td>
          <td>{{ event.time }}</td>
          <td>{{ event.ip_address }}</td>
          <td>{{ event.ip_address.hashed_ip_address }}</td>
          <td>{{ event.location_info }}</td>
          <td>{{ event.user_agent_info }}</td>
          <td>{{ event.additional }}</td>
        </tr>
        {% endfor %}
      </tbody>
    </table>
  </div>
</div> <!-- .card #projectActivity -->

<div class="card card-primary card-outline collapsed-card" id="reindex">
  <div class="card-header">
    <h3 class="card-title">Reindex Project</h3>
    <div class="card-tools">
      <button type="button" class="btn btn-tool" data-card-widget="collapse"><i class="fas fa-plus"></i>
      </button>
    </div>
  </div>

  <div class="card-body">
    <p>Trigger reindex for this project</p>
  </div>

  <div class="card-footer">
    <div class="float-right">
      <form method="GET" action="{{ request.route_path('admin.project.reindex', project_name=project.normalized_name) }}">
        <button type="submit" class="btn btn-primary">Reindex</button>
      </form>
    </div>
  </div>
</div> <!-- .card #reindex -->

<form method="GET" action="{{ request.route_path('admin.prohibited_project_names.add') }}">
  <input name="project" type="hidden" value="{{ project.normalized_name }}">
  <div class="card card-warning card-outline collapsed-card" id="prohibitedProjectName">
    <div class="card-header">
      <h3 class="card-title">Prohibit Project Name</h3>
      <div class="card-tools">
        <button type="button" class="btn btn-tool" data-card-widget="collapse"><i class="fas fa-plus"></i>
        </button>
      </div>
    </div>

    <div class="card-body">
      <div class="form-group col-sm-12">
        <label for="prohibitedComment">Comment</label>
        <textarea name="comment" class="form-control" id="prohibitedComment" rows="3" placeholder="Enter comment ..." {{ "disabled" if not request.has_permission(Permissions.AdminProhibitedProjectsWrite) }}></textarea>
      </div>
    </div>

    <div class="card-footer">
      <div class="float-right">
        <button type="submit" class="btn btn-primary" title="{{ 'Submitting requires superuser privileges' if not request.has_permission(Permissions.AdminProhibitedProjectsWrite) }}" {{ "disabled" if not request.has_permission(Permissions.AdminProhibitedProjectsWrite) }}>Submit</button>
      </div>
    </div>
  </div>
</form> <!-- .card #prohibitedProjectName -->

<div class="card card-warning card-outline collapsed-card" id="archivedProjectName">
  <div class="card-header">
    <h3 class="card-title">Archive project</h3>
    <div class="card-tools">
      <button type="button" class="btn btn-tool" data-card-widget="collapse"><i class="fas fa-plus"></i>
      </button>
    </div>
  </div>

  <div class="card-footer">
    <div class="float-right">
      {% if project.lifecycle_status in ["archived", "archived-noindex"] %}
        <form method="POST" action="{{ request.route_path('admin.project.unarchive', project_name=project.name) }}">
          <input name="csrf_token" type="hidden" value="{{ request.session.get_csrf_token() }}">
          <button type="submit" class="btn btn-primary" title="{{ 'Unarchiving requires superuser privileges' if not request.has_permission(Permissions.AdminProjectsWrite) }}" {{ "disabled" if not request.has_permission(Permissions.AdminProjectsWrite) }}>
            Unarchive project
          </button>
        </form>
      {% else %}
        <form method="POST" action="{{ request.route_path('admin.project.archive', project_name=project.name) }}">
          <input name="csrf_token" type="hidden" value="{{ request.session.get_csrf_token() }}">
          <button type="submit" class="btn btn-primary {{ 'btn-disabled' if project.lifecycle_status == 'quarantine' }}" title="{{ 'Archiving requires superuser privileges' if not request.has_permission(Permissions.AdminProjectsWrite) }}" {{ "disabled" if not request.has_permission(Permissions.AdminProjectsWrite) }}>
            Archive project
          </button>
        </form>
      {% endif %}
    </div>
  </div>
</div>

<!-- Deletion form -->
{% include 'delete.html' %}

{% endblock %}
